/**
 * Created by chaoCheng on 2017/1/13.
 */
function PlayPlanAddController(PlayPlan,$uibModal,$scope,$state,$stateParams){
    var vm=this;
    vm.playplan={"planName":$stateParams.planName,"id":$stateParams.planId}
    $scope.readDrivingUnable=true;
    vm.isSend = false;
    vm.add=function(){
        vm.isSend = true;
        vm.queryParams = _.clone($stateParams)
        PlayPlan.add(vm.playplan).$promise.then(function(response){
            //处理add之后的返回结果
            if(response.success != null) {
                // 模拟窗口打开之后执行该函数
                var modalInstance = $uibModal.open({
                    templateUrl: 'myModalContent.html',
                    controller: 'ModalInstanceCtrl',
                    size: PlayPlan
                });
                // 模拟窗口关闭后回传调用
                modalInstance.result.then(function () {
                   // $state.go('detail', {'planId':response.planId})
                    $state.go('playplan');
                });
                vm.isSend = false;
            } else {
                $scope.serverError = response.fail
                $("#error").show();
            }
        })
    }


    vm.cancel = function() {
        $state.go('playplan', vm.queryParams);
    }
    vm.invalid = function(){
        if($("#planName").val()==""){
            $("#error").hide();
        }else{
            vm.isSend = false;
        }
    }
}

